<?php include  APP_PATH.'../template/public/header.php'?>
<aside class="main-sidebar">
    <section class="sidebar">
        <?php include APP_PATH.'../template/public/navigation.php'?>
    </section>
</aside>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            {$title}
        </h1>

        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> {$title}</a></li>
        </ol>
    </section>
    <section class="content">


        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title">广告组</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
                <form id="group_form" role="form">
                    <input name="id"  class="layui-hide" value="{$plan.id}"/>
                    <div class="form-group">
                        <div class="btn-group">
                            <button id="choose_show" type="button" class="btn btn-info">选择广告组</button>
                            <button id="new_show" type="button" class="btn btn-default">新建广告组</button>
                        </div>
                    </div>
                    <div id="choose" class="col-md-4">
                        <div class="form-group">
                            <label>选择已有广告组</label>
                            <select id="group_id" name="attr_adv_group_id" class="form-control select2"  style="width: 100%;">
                                {foreach $group as $g}
                                <option value="{$g.id}">{$g.group_name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="form-group">
                            <label>日预算</label>
                            <input id="budget"   type="text" class="form-control" disabled>
                        </div>
                        <div class="form-group">
                            <label>平台</label>
                            <input  id="plat"  type="text" class="form-control" disabled>
                        </div>
                    </div>
                    <div id="new" class="layui-hide col-md-4" >
                        <div class="form-group" >
                            <label>广告组名</label>
                            <input name="group_name" type="text" class="form-control" placeholder="" >
                        </div>
                        <div class="form-group">
                            <label>日预算</label>
                            <label>
                                <input value="0" type="radio" name="group_budget_type" class="flat-red" checked  >
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio"  name="group_budget_type" class="flat-red" >
                                自定义
                                <span  id="amount" class="layui-hide"><input  name="amount" type="text"   placeholder="输入金额不低于300元" >元</span>
                            </label>
                        </div>
                        <div class="form-group">
                            <label>平台</label>
                            <label>
                                <input value="移动端" type="radio" name="group_platform" class="flat-red" checked >
                                移动端
                            </label>
                        </div>
                    </div>
                </form>
            </div>
            <!-- /.box-body -->
            <div class="box-header with-border">
                <h3 class="box-title">广告计划</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
                <div class="col-md-8">
                    <form id="plan_from"  role="form">
                        <label>广告名称</label>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">计划名称</span>
                            <input name="plan_name" type="text" class="form-control" placeholder="计划名称" value="{$plan.plan_name}">
                        </div>
                        <br>
                        <label>投放平台</label>
                        <div class="input-group col-md-8">
                            平台
                            <label>
                                <input value="移动端" type="radio" name="platform" class="flat-red" checked>
                                移动端
                            </label>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            渠道
                            <label>
                                <input value="0" type="radio" name="channel_type" class="flat-red" checked>
                                全选
                            </label>
                            <label>
                                <input value="1" type="radio" name="channel_type" class="flat-red" >
                                自定义
                            </label>
                            <label>
                                <input value="2" type="radio" name="channel_type" class="flat-red" >
                                地方头条
                            </label>
                        </div>
                        <br>
                        <div id="channel_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $channel as $ch}
                                <label id="cha_{$ch.id}" cha="{$ch.name}">
                                    <input  value="{$ch.id}" type="checkbox" name="costom_channel_id" class="flat-red" >
                                    {$ch.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="channel" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <br>

                        <div class="input-group col-md-8">
                            系统
                            <label>
                                <input value="Android" type="checkbox" name="system" class="flat-red"  >
                                Android
                            </label>
                            <label>
                                <input value="iOS" type="checkbox" name="system" class="flat-red" >
                                iOS
                            </label>
                        </div>
                        <br>
                        <label>广告创意</label>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">选择样式</span>
                            <select  id="adv_style" name="style" class="form-control" style="width: 100%;">
                                <option value="0" selected="selected">请选择样式</option>
                                {foreach $style as $st}
                                <option value="{$st.id}">{$st.style_name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">推广链接</span>
                            <input name="promote_links" type="text" class="form-control" placeholder="" value="{$plan.promote_links}">
                        </div>
                        <br>
                        <div id="adv_title" class="layui-hide">
                            <div class="input-group col-md-8">
                                <span class="input-group-addon">创意标题</span>
                                <input name="title" type="text" class="form-control" placeholder="" value="{$plan.title}">
                            </div>
                            <br>
                            <div class="input-group col-md-8">
                                <span class="input-group-addon">副标题</span>
                                <input name="subtitle" type="text" class="form-control" placeholder="" value="{$plan.subtitle}">
                            </div>
                            <br>
                        </div>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">来源</span>
                            <input name="source" type="text" class="form-control" placeholder="" value="{$plan.source}">
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">广告主名称</span>
                            <select  name="attr_adv_user_id" class="form-control" style="width: 100%;">
                                <option value="" selected="selected"></option>
                                {foreach $advertisers as $adv}
                                <option value="{$adv.user_id}" >{$adv.advertisers_name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <input type="hidden" name="material" id="material" value="{$plan.material}">
                            <div class="layui-upload">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="image1">
                                </div>
                                <button type="button" class="layui-btn layui-btn-primary" id="bannerBtn1"><i class="icon icon-upload3"></i>点击上传素材</button>
                                <p>目前支持 gif | jpg | png 等图片文件上传，文件大小2M以内</p>
                                <p id="demoText1"></p>
                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">广告分类</span>
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $industry as $in}
                                <label id="inst_{$in.id}" inst="{$in.name}">
                                    <input  value="{$in.id}" type="radio" name="category" class="flat-red" >
                                    {$in.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="category" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">
                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            推广目标：
                            <label>
                                <input value="0" type="radio" name="target_type" class="flat-red" checked>
                                网页
                            </label>
                            <label>
                                <input value="1" type="radio" name="target_type" class="flat-red" >
                                应用下载
                            </label>
                            <label>
                                <input value="2" type="radio" name="target_type" class="flat-red" >
                                唤醒应用
                            </label>
                        </div>
                        <br>
                        <div id="app_xz" class="layui-hide">
                            <div class="input-group col-md-8">
                                <span class="input-group-addon">下载链接：</span>
                                <input name="download_link" type="text" class="form-control" placeholder="" value="{$plan.download_link}">
                            </div>
                            <br>
                            <div class="input-group col-md-8">
                                <span class="input-group-addon">应用包名：</span>
                                <input name="app_name" type="text" class="form-control" placeholder="" value="{$plan.app_name}">
                            </div>
                            <br>
                            <div class="input-group col-md-8">
                                <span class="input-group-addon">AppStoreID：</span>
                                <input name="AppStoreID" type="text" class="form-control" placeholder="" value="{$plan.AppStoreID}">
                            </div>
                            <br>
                        </div>
                        <div id="hx_app" class="layui-hide">
                            <div class="input-group col-md-8">
                                <span class="input-group-addon">唤醒链接(Android)：</span>
                                <input name="rouse_link_android" type="text" class="form-control" placeholder="" value="{$plan.rouse_link_android}">
                            </div>
                            <br>
                            <div class="input-group col-md-8">
                                <span class="input-group-addon">唤醒链接(iOS)：</span>
                                <input name="rouse_link_ios" type="text" class="form-control" placeholder="" value="{$plan.rouse_link_ios}">
                            </div>
                            <br>
                        </div>
                        <br>
                        <label>广告定向</label>
                        <div class="input-group col-md-8">
                            性别：
                            <label>
                                <input value="不限" type="radio" name="sex" class="flat-red" checked>
                                不限
                            </label>
                            <label>
                                <input value="男" type="radio" name="sex" class="flat-red" >
                                男
                            </label>
                            <label>
                                <input value="女" type="radio" name="sex" class="flat-red" >
                                女
                            </label>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            投放地域：
                            <label>
                                <input value="0" type="radio" name="regional_type" class="flat-red" checked>
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio" name="regional_type" class="flat-red" >
                                自定义
                            </label>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            年龄：
                            <label>
                                <input value="不限" type="radio" name="age" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="0-17" type="checkbox" name="age" class="flat-red" >
                                0-17
                            </label>
                            <label>
                                <input value="18-24" type="checkbox" name="age" class="flat-red" >
                                18-24
                            </label>
                            <label>
                                <input value="25-34" type="checkbox" name="age" class="flat-red" >
                                25-34
                            </label>
                            <label>
                                <input value="35-44" type="checkbox" name="age" class="flat-red" >
                                35-44
                            </label>
                            <label>
                                <input value="1" type="checkbox" name="age" class="flat-red" >
                                45+
                            </label>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            网络环境：
                            <label>
                                <input value="不限" type="radio" name="network_env" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="2G" type="checkbox" name="network_env" class="flat-red" >
                                2G
                            </label>
                            <label>
                                <input value="3G" type="checkbox" name="network_env" class="flat-red" >
                                3G
                            </label>
                            <label>
                                <input value="4G" type="checkbox" name="network_env" class="flat-red" >
                                4G
                            </label>
                            <label>
                                <input value="5G" type="checkbox" name="network_env" class="flat-red" >
                                5G
                            </label>
                            <label>
                                <input value="WIFI" type="checkbox" name="network_env" class="flat-red" >
                                WIFI
                            </label>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            网络运营商：
                            <label>
                                <input value="不限" type="radio" name="network_ope" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="中国移动" type="checkbox" name="network_ope" class="flat-red" >
                                中国移动
                            </label>
                            <label>
                                <input value="中国联通" type="checkbox" name="network_ope" class="flat-red" >
                                中国联通
                            </label>
                            <label>
                                <input value="中国电信" type="checkbox" name="network_ope" class="flat-red" >
                                中国电信
                            </label>

                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            手机品牌：
                            <label>
                                <input value="0" type="radio" name="phone_brand_type" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio" name="phone_brand_type" class="flat-red" >
                                自定义
                            </label>
                        </div>
                        <div id="phone_brand_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $brand as $br}
                                <label id="bra_{$br.id}" bra="{$br.name}">
                                    <input  value="{$br.id}" type="checkbox" name="phone_brand_id" class="flat-red" >
                                    {$br.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="phone_brand" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            安装应用偏好：
                            <label>
                                <input value="0" type="radio" name="apply_bias_type" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio" name="apply_bias_type" class="flat-red" >
                                自定义
                            </label>
                        </div>
                        <div id="apply_bias_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $apply_bias as $bias}
                                <label id="apply_{$bias.id}" int="{$bias.name}">
                                    <input  value="{$bias.id}" type="checkbox" name="custom_apply_bias" class="flat-red" >
                                    {$bias.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="apply_bias" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            已安装APP定向：
                            <label>
                                <input value="0" type="radio" name="install_app_type" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio" name="install_app_type" class="flat-red" >
                                自定义
                            </label>
                            <label>
                                <input value="2" type="radio" name="install_app_type" class="flat-red" >
                                按APP
                            </label>
                        </div>
                        <div id="install_app_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $app_custom as $app}
                                <label id="install_{$app.id}" int="{$app.name}">
                                    <input  value="{$app.id}" type="checkbox" name="custom_install_app" class="flat-red" >
                                    {$app.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="install_app" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <div id="appins_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $apps as $app}
                                <label id="appins_{$app.id}" int="{$app.name}">
                                    <input  value="{$app.id}" type="checkbox" name="press_install_app" class="flat-red" >
                                    {$app.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="appins" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            未安装APP定向：
                            <label>
                                <input value="0" type="radio" name="uninstall_app_type" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio" name="uninstall_app_type" class="flat-red" >
                                自定义
                            </label>
                            <label>
                                <input value="2" type="radio" name="uninstall_app_type" class="flat-red" >
                                按APP
                            </label>
                        </div>

                        <div id="uninstall_app_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $app_custom as $app}
                                <label id="uninstall_{$app.id}" int="{$app.name}">
                                    <input  value="{$app.id}" type="checkbox" name="custom_uninstall_app" class="flat-red" >
                                    {$app.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="uninstall_app" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>

                        <div id="appunins_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $apps as $app}
                                <label id="appunins_{$app.id}" int="{$app.name}">
                                    <input  value="{$app.id}" type="checkbox" name="press_uninstall_app" class="flat-red" >
                                    {$app.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="appunins" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            广告点击偏好：
                            <label>
                                <input value="0" type="radio" name="click_bias_type" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio" name="click_bias_type" class="flat-red" >
                                自定义
                            </label>
                        </div>
                        <div id="click_bias_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $click_bias as $bias}
                                <label id="click_{$bias.id}" int="{$bias.name}">
                                    <input  value="{$bias.id}" type="checkbox" name="custom_click_bias" class="flat-red" >
                                    {$bias.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="click_bias" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            兴趣定向：
                            <label>
                                <input value="0" type="radio" name="interest_type" class="flat-red"  checked>
                                不限
                            </label>
                            <label>
                                <input value="1" type="radio" name="interest_type" class="flat-red" >
                                用户阅读兴趣
                            </label>
                        </div>
                        <br>
                        <div id="interest_show" class="input-group col-md-8 layui-hide">
                            <div  style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left;">
                                {foreach $interest as $in}
                                <label id="int_{$in.id}" int="{$in.name}">
                                    <input  value="{$in.id}" type="checkbox" name="interest_id" class="flat-red" >
                                    {$in.name}
                                </label>
                                <br>
                                {/foreach}
                            </div>
                            <div id="interest" style="height: 250px;width: 150px;overflow-y:scroll;border:1px solid #000000;float: left">

                            </div>
                        </div>
                        <br>
                        <label>广告预算和出价</label>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">投放位置</span>
                            <select id="put_location"  name="put_location" class="form-control" style="width: 100%;">
                                <option selected="selected">请先选择样式</option>
                            </select>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">广告预算</span>
                            <select  name="budget_type" class="form-control" style="width: 100%;">
                                <option value="0" selected="selected">总预算</option>
                                <option value="1">日预算</option>
                            </select>
                            <input name="budget_amoont" type="text" class="form-control" placeholder="多少元" value="{$plan.budget_amoont}">
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <label>
                                <input value="0" type="radio" name="put_type" class="flat-red"  checked>
                                立即长期投放
                            </label>
                            <label>
                                <input value="1" type="radio" name="put_type" class="flat-red" >
                                自定义
                            </label>
                        </div>
                        <div id="put_time" class="input-group col-md-8 layui-hide">
                            <div class="input-daterange input-group" id="reservation">
                                <input type="text" class="input-sm form-control" name="put_start_time" id="begin_time" value="{$plan.put_start_time}"/>
                                <span class="input-group-addon">到</span>
                                <input type="text" class="input-sm form-control" name="put_end_time" id="end_time" value="{$plan.put_end_time}"/>
                            </div>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            付费方式
                            <label>
                                <input value="0" type="radio" name="pay_type" class="flat-red"  checked>
                                CPM(每千次展现出价)
                            </label>
                            <label>
                                <input value="1" type="radio" name="pay_type" class="flat-red" >
                                CPC(每次点击出价)
                            </label>
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">出价</span>
                            <input name="pay_amount" type="text" class="form-control" placeholder="多少元" value="{$plan.pay_amount}">
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">展现频次：</span>
                            <input name="frequency" type="text" class="form-control" placeholder="" value="{$plan.frequency}">
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">展现次数：</span>
                            <input name="see_num" type="text" class="form-control" placeholder="" value="{$plan.see_num}">
                        </div>
                        <br>
                        <div class="input-group col-md-8">
                            <span class="input-group-addon">点击次数：</span>
                            <input name="click_num" type="text" class="form-control" placeholder="" value="{$plan.click_num}">
                        </div>
                        <br>
                        <div class="col-md-2">
                            <button id="submit" class="btn btn-block btn-info">保存</button>
                        </div>
                        <div class="col-md-2">
                            <button type="reset" class="btn btn-block btn-default">取消</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    </section>
</div>
<?php include APP_PATH.'../template/public/footer.php'; ?>
<script>
    layui.use('upload', function() {
        var $ = layui.jquery
            , upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#bannerBtn1'
            ,url: '{:url("admin/UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#image1').attr('src', result);
                    $('#image1').attr('style','height: 350px;width: 220px')
                });
            },

            done: function(res){
                if(res.code>0){
                    $('#material').val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }

        });
    });
    //提交表单
    $('#submit').click(function () {
        var data = {};
        var g = $('#group_form').serializeArray();
        $.each(g, function () {
            data[this.name] = this.value;
        });
        var p = $('#plan_from').serializeArray();
        $.each(p, function () {
            if($('input[name="'+this.name+'"]:checked').attr('type')=='checkbox'){
                var a = [];
                $('input[name="'+this.name+'"]:checked').each(function () {
                    a.push($(this).val());
                });
                data[this.name]=a.join(',');
            }else{
                data[this.name] = this.value;
            }
        });
        console.log(data);
        if(data.attr_adv_user_id==''){
            layer.msg('广告主名称不能空', {time: 1800, icon: 2});
            $("html,body").animate({scrollTop: $('select[name="attr_adv_user_id"]').offset().top-200+'px'}, 1000);
            return false;
        }
        if(data.plan_name==''){
            layer.msg('计划名称不能空', {time: 1800, icon: 2});
            $("html,body").animate({scrollTop: $('input[name="plan_name"]').offset().top-100+'px'}, 1000);
            return false;
        }

        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.post("{:url('add_plan_check')}", data, function (res) {
            layer.close(loading);
            if (res.code > 0) {
                layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                    location.href = res.url;
                });
            } else {
                layer.msg(res.msg, {time: 1800, icon: 2});
            }
        });
        return false;
    });
    function cc(id) {
        $('input:radio[name="category"][value="'+id+'"]').iCheck('uncheck');
        $('#category').empty();
    }
    function del_div(id,div) {
        $('input:checkbox[name="'+div+'"][value="'+id+'"]').iCheck('uncheck');
        $('#'+div+id).remove();
    }
    $(function () {
        $('.select2').select2();
        $('#reservation').datepicker({
            language: 'zh-CN',//显示中文
            format: 'yyyy-mm-dd',//显示格式
        });
        //
        $('input:radio[name="put_type"]').on('ifChanged',function (){
            var type=$('input:radio[name="put_type"]:checked').val();
            if(type==1){
                $('#put_time').removeClass('layui-hide');
            }else{
                $('#put_time').addClass('layui-hide');
                $('#put_time input').val('');
            }
        });
        //
        //广告组选择日预算设置金额
        $('input[name="group_budget_type"]').on('ifChanged',function () {
            var nr=$('input[name="group_budget_type"]:checked').val();
            if(nr==0){
                $('#amount').addClass('layui-hide');
            }else {
                $('#amount').removeClass('layui-hide');
            }
        });
        //选中自定义广告点击偏好
        $('input:radio[name="click_bias_type"]').on('ifChanged',function (){
            var type=$('input:radio[name="click_bias_type"]:checked').val();
            if(type==1){
                $('#click_bias_show').removeClass('layui-hide');
            }else{
                $('#click_bias').empty();
                $('#click_bias_show').addClass('layui-hide');
                $('input:checkbox[name="custom_click_bias"]').iCheck('uncheck');
            }
        });
        $('input:checkbox[name="custom_click_bias"]').on('ifChanged',function () {
            $('#click_bias').empty();
            var div='custom_click_bias';
            $.each($('input:checkbox[name="custom_click_bias"]:checked'),function(){
                var v=$(this).val();
                var t=$('#click_'+v).attr('int');
                $('#click_bias').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });
        //选中自定义安装应用偏好
        $('input:radio[name="apply_bias_type"]').on('ifChanged',function (){
            var type=$('input:radio[name="apply_bias_type"]:checked').val();
            if(type==1){
                $('#apply_bias_show').removeClass('layui-hide');
            }else{
                $('#apply_bias').empty();
                $('#apply_bias_show').addClass('layui-hide');
                $('input:checkbox[name="custom_apply_bias"]').iCheck('uncheck');
            }
        });
        $('input:checkbox[name="custom_apply_bias"]').on('ifChanged',function () {
            $('#apply_bias').empty();
            var div='custom_apply_bias';
            $.each($('input:checkbox[name="custom_apply_bias"]:checked'),function(){
                var v=$(this).val();
                var t=$('#apply_'+v).attr('int');
                $('#apply_bias').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });
        //选中自定义已安装APP定向
        $('input:radio[name="install_app_type"]').on('ifChanged',function () {
            var type=$('input:radio[name="install_app_type"]:checked').val();
            if(type==1){
                $('#install_app_show').removeClass('layui-hide');
                $('#appins').empty();
                $('#appins_show').addClass('layui-hide');
                $('input:checkbox[name="press_install_app"]').iCheck('uncheck');
            }else  if(type==2){
                $('#uninstall_app').empty();
                $('#uninstall_app_show').addClass('layui-hide');
                $('input:checkbox[name="custom_install_app"]').iCheck('uncheck');
                $('#appins_show').removeClass('layui-hide');
            }else{
                $('#install_app').empty();
                $('#install_app_show').addClass('layui-hide');
                $('input:checkbox[name="custom_install_app"]').iCheck('uncheck');
                $('#appins').empty();
                $('#appins_show').addClass('layui-hide');
                $('input:checkbox[name="press_install_app"]').iCheck('uncheck');
            }
        });
        $('input:checkbox[name="custom_install_app"]').on('ifChanged',function () {
            $('#install_app').empty();
            var div='custom_install_app';
            $.each($('input:checkbox[name="custom_install_app"]:checked'),function(){
                var v=$(this).val();
                var t=$('#install_'+v).attr('int');
                $('#install_app').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });
        $('input:checkbox[name="press_install_app"]').on('ifChanged',function () {
            $('#appins').empty();
            var div='press_install_app';
            $.each($('input:checkbox[name="press_install_app"]:checked'),function(){
                var v=$(this).val();
                var t=$('#appins_'+v).attr('int');
                $('#appins').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });

        //选中自定义未安装APP定向
        $('input:radio[name="uninstall_app_type"]').on('ifChanged',function () {
            var type=$('input:radio[name="uninstall_app_type"]:checked').val();
            if(type==1){
                $('#uninstall_app_show').removeClass('layui-hide');
                $('#appunins').empty();
                $('#appunins_show').addClass('layui-hide');
                $('input:checkbox[name="press_uninstall_app"]').iCheck('uncheck');
            }else if(type==2){
                $('#uninstall_app').empty();
                $('#uninstall_app_show').addClass('layui-hide');
                $('input:checkbox[name="custom_uninstall_app"]').iCheck('uncheck');
                $('#appunins_show').removeClass('layui-hide');
            }else{
                $('#uninstall_app').empty();
                $('#uninstall_app_show').addClass('layui-hide');
                $('input:checkbox[name="custom_uninstall_app"]').iCheck('uncheck');
                $('#appunins').empty();
                $('#appunins_show').addClass('layui-hide');
                $('input:checkbox[name="press_uninstall_app"]').iCheck('uncheck');
            }
        });
        $('input:checkbox[name="custom_uninstall_app"]').on('ifChanged',function () {
            $('#uninstall_app').empty();
            var div='custom_uninstall_app';
            $.each($('input:checkbox[name="custom_uninstall_app"]:checked'),function(){
                var v=$(this).val();
                var t=$('#uninstall_'+v).attr('int');
                $('#uninstall_app').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });
        $('input:checkbox[name="press_uninstall_app"]').on('ifChanged',function () {
            $('#appunins').empty();
            var div='press_uninstall_app';
            $.each($('input:checkbox[name="press_uninstall_app"]:checked'),function(){
                var v=$(this).val();
                var t=$('#appunins_'+v).attr('int');
                $('#appunins').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });
        //选中用户阅读兴趣定向
        $('input:radio[name="interest_type"]').on('ifChanged',function () {
            var type=$('input:radio[name="interest_type"]:checked').val();
            if(type==1){
                $('#interest_show').removeClass('layui-hide');
            }else {
                $('#interest').empty();
                $('#interest_show').addClass('layui-hide');
                $('input:checkbox[name="interest_id"]').iCheck('uncheck');
            }
        });
        $('input:checkbox[name="interest_id"]').on('ifChanged',function () {
            $('#interest').empty();
            var div='interest_id';
            $.each($('input:checkbox[name="interest_id"]:checked'),function(){
                var v=$(this).val();
                var t=$('#int_'+v).attr('int');
                $('#interest').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });

        //推广目标选中
        $('input:radio[name="target_type"]').on('ifChanged',function () {
            var type=$('input:radio[name="target_type"]:checked').val();
            if(type==1){
                $('#app_xz').removeClass('layui-hide');
                $('#hx_app').addClass('layui-hide');
                $('#app_xz input').removeAttr('disabled');
                $('#hx_app input').val('');
                $('#hx_app input').attr('disabled',true);
            }else if(type==2){
                $('#hx_app').removeClass('layui-hide');
                $('#app_xz').addClass('layui-hide');
                $('#hx_app input').removeAttr('disabled');
                $('#app_xz input').attr('disabled',true);
            }else {
                $('#hx_app').addClass('layui-hide');
                $('#app_xz').addClass('layui-hide');
                $('#app_xz input').attr('disabled',true);
                $('#hx_app input').attr('disabled',true);
                $('#hx_app input').val('');
                $('#app_xz input').val('');
            }
        });
        //选中广告分类
        $('input:radio[name="category"]').on('ifChecked',function () {
            $('#category').empty();
            var v=$('input:radio[name="category"]:checked').val();
            var t=$('#inst_'+v).attr('inst');
            $('#category').append(' <div>'+t+'<button  onclick="cc('+v+')" type="button"  aria-hidden="true">&times;</button></div>');
        });

        //选中自定义渠道
        $('input:radio[name="channel_type"]').on('ifChecked',function () {
            var c=  $('input:radio[name="channel_type"]:checked').val();
            if(c==1){
                $('#channel_show').removeClass('layui-hide');
            }else {
                $('#channel').empty();
                $('#channel_show').addClass('layui-hide');
                $('input:checkbox[name="costom_channel_id"]').iCheck('uncheck');
            }
        });
        $('input:checkbox[name="costom_channel_id"]').on('ifChanged',function () {
            $('#channel').empty();
            var div='costom_channel_id';
            $.each($('input:checkbox[name="costom_channel_id"]:checked'),function(){
                var v=$(this).val();
                var t=$('#cha_'+v).attr('cha');
                $('#channel').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });
        //选中自定义手机品牌
        $('input:radio[name="phone_brand_type"]').on('ifChecked',function () {
            var c=  $('input:radio[name="phone_brand_type"]:checked').val();
            if(c==1){
                $('#phone_brand_show').removeClass('layui-hide');
            }else {
                $('#phone_brand').empty();
                $('#phone_brand_show').addClass('layui-hide');
                $('input:checkbox[name="phone_brand_id"]').iCheck('uncheck');
            }
        });
        $('input:checkbox[name="phone_brand_id"]').on('ifChanged',function () {
            $('#phone_brand').empty();
            var div='phone_brand_id';
            $.each($('input:checkbox[name="phone_brand_id"]:checked'),function(){
                var v=$(this).val();
                var t=$('#bra_'+v).attr('bra');
                $('#phone_brand').append(' <div id="'+div+v+'">'+t+'<button  onclick="del_div('+v+',\''+div+'\')" type="button"  aria-hidden="true">&times;</button></div>');
            });
        });

        $('input:radio[name="age"]').on('ifChecked',function(){
            $('input:checkbox[name="age"]').iCheck('uncheck');
        });
        $('input:checkbox[name="age"]').on('ifChecked',function(){
            $('input:radio[name="age"]').iCheck('uncheck');
        });
        $('input:radio[name="network_env"]').on('ifChecked',function(){
            $('input:checkbox[name="network_env"]').iCheck('uncheck');
        });
        $('input:checkbox[name="network_env"]').on('ifChecked',function(){
            $('input:radio[name="network_env"]').iCheck('uncheck');
        });
        $('input:radio[name="network_ope"]').on('ifChecked',function(){
            $('input:checkbox[name="network_ope"]').iCheck('uncheck');
        });
        $('input:checkbox[name="network_ope"]').on('ifChecked',function(){
            $('input:radio[name="network_ope"]').iCheck('uncheck');
        });
        //将广告信息填充
        $('#group_id').val('{$plan.attr_adv_group_id}').trigger('change');
        var channel_type='{$plan.channel_type}';
        if(channel_type){
            $('input:radio[name="channel_type"][value="'+channel_type+'"]').iCheck('check');
        }

        var channel_id='{$plan.costom_channel_id}';
        if(channel_id){
            var a=channel_id.split(',');
            a.forEach(function(e){
                $('input:checkbox[name="costom_channel_id"][value="'+e+'"]').iCheck('check');
            });
        }
        var system='{$plan.system}';
        if(system){
            var a=system.split(',');
            a.forEach(function(e){
                $('input:checkbox[name="system"][value="'+e+'"]').iCheck('check');
            });
        }
        var category='{$plan.category}';
        if(category){
            $('input:radio[name="category"][value="'+category+'"]').iCheck('check');
        }
        var sex='{$plan.sex}';
        if(sex){
            $('input:radio[name="sex"][value="'+sex+'"]').iCheck('check');
        }
        var age='{$plan.age}';
        if(age){
            var a=age.split(',');
            a.forEach(function(e){
                $('input[name="age"][value="'+e+'"]').iCheck('check');
            });
        }
        var network_env='{$plan.network_env}';
        if(network_env){
            var a=network_env.split(',');
            a.forEach(function(e){
                $('input[name="network_env"][value="'+e+'"]').iCheck('check');
            });
        }
        var network_ope='{$plan.network_ope}';
        if(network_ope){
            var a=network_ope.split(',');
            a.forEach(function(e){
                $('input[name="network_ope"][value="'+e+'"]').iCheck('check');
            });
        }
        var phone_brand_type='{$plan.phone_brand_type}';
        if(phone_brand_type){
            $('input[name="phone_brand_type"][value="'+phone_brand_type+'"]').iCheck('check');
        }
        var phone_brand_id='{$plan.phone_brand_id}';
        if(phone_brand_id){
            var a=phone_brand_id.split(',');
            a.forEach(function(e){
                $('input[name="phone_brand_id"][value="'+e+'"]').iCheck('check');
            });
        }
        var phone_brand_type='{$plan.phone_brand_type}';
        if(phone_brand_type){
            $('input[name="phone_brand_type"][value="'+phone_brand_type+'"]').iCheck('check');
        }
        var apply_bias_type='{$plan.apply_bias_type}';
        if(apply_bias_type){
            $('input[name="apply_bias_type"][value="'+apply_bias_type+'"]').iCheck('check');
        }
        var custom_apply_bias='{$plan.custom_apply_bias}';
        if(custom_apply_bias){
            var a=custom_apply_bias.split(',');
            a.forEach(function(e){
                $('input[name="custom_apply_bias"][value="'+e+'"]').iCheck('check');
            });
        }
        var install_app_type='{$plan.install_app_type}';
        if(install_app_type){
            $('input[name="install_app_type"][value="'+install_app_type+'"]').iCheck('check');
        }
        var custom_install_app='{$plan.custom_install_app}';
        if(custom_install_app){
            var a=custom_install_app.split(',');
            a.forEach(function(e){
                $('input[name="custom_install_app"][value="'+e+'"]').iCheck('check');
            });
        }
        var press_install_app='{$plan.press_install_app}';
        if(press_install_app){
            var a=press_install_app.split(',');
            a.forEach(function(e){
                $('input[name="press_install_app"][value="'+e+'"]').iCheck('check');
            });
        }
        var uninstall_app_type='{$plan.uninstall_app_type}';
        if(uninstall_app_type){
            $('input[name="uninstall_app_type"][value="'+uninstall_app_type+'"]').iCheck('check');
        }
        var custom_uninstall_app='{$plan.custom_uninstall_app}';
        if(custom_uninstall_app){
            var a=custom_uninstall_app.split(',');
            a.forEach(function(e){
                $('input[name="custom_uninstall_app"][value="'+e+'"]').iCheck('check');
            });
        }
        var press_uninstall_app='{$plan.press_uninstall_app}';
        if(press_uninstall_app){
            var a=press_uninstall_app.split(',');
            a.forEach(function(e){
                $('input[name="press_uninstall_app"][value="'+e+'"]').iCheck('check');
            });
        }
        var click_bias_type='{$plan.click_bias_type}';
        if(click_bias_type){
            $('input[name="click_bias_type"][value="'+click_bias_type+'"]').iCheck('check');
        }
        var custom_click_bias='{$plan.custom_click_bias}';
        if(custom_click_bias){
            var a=custom_click_bias.split(',');
            a.forEach(function(e){
                $('input[name="custom_click_bias"][value="'+e+'"]').iCheck('check');
            });
        }
        var interest_type='{$plan.interest_type}';
        if(interest_type){
            $('input[name="interest_type"][value="'+interest_type+'"]').iCheck('check');
        }
        var interest_id='{$plan.interest_id}';
        if(interest_id){
            var a=interest_id.split(',');
            a.forEach(function(e){
                $('input[name="interest_id"][value="'+e+'"]').iCheck('check');
            });
        }
        $('#adv_style').val('{$plan.style}').trigger('change');
        $('#put_location').append("<option value='{$plan.put_location}' selected='selected'>{$plan.put_location}</option>");
        var target_type='{$plan.target_type}';
        if(target_type){
            $('input[name="target_type"][value="'+target_type+'"]').iCheck('check');
        }
        var put_type='{$plan.put_type}';
        if(put_type){
            $('input[name="put_type"][value="'+put_type+'"]').iCheck('check');
        }
        var pay_type='{$plan.pay_type}';
        if(pay_type){
            $('input[name="pay_type"][value="'+pay_type+'"]').iCheck('check');
        }
        if('{$plan.material}'){
            $('#image1').attr('src', '<?php echo GETIMG_PATH.$plan["material"];?>');
            $('#image1').attr('style','height: 350px;width: 220px')
        }

        //初始化icheck插件
        $('input[type="radio"].flat-red,input[type="checkbox"].flat-red').iCheck({
            checkboxClass: 'iradio_square-green',
            radioClass   : 'iradio_square-green'
        });
        $('#new input').attr('disabled','true');

    });
    $('#new_show').click(function () {
        $('#new').removeClass('layui-hide');
        $('#choose').addClass('layui-hide');
        $('#group_id').attr('disabled','true');
        $('#new input').removeAttr('disabled');
        $('#new_show').removeClass('btn-default');
        $('#new_show').addClass('btn-info');
        $('#choose_show select').attr('disabled','true');
        $('#choose_show').removeClass('btn-info');
        $('#choose_show').addClass('btn-default');
        $('select[name="attr_adv_user_id"]').val('');
        $('select[name="attr_adv_user_id"]').removeAttr('disabled');

    });
    $('#choose_show').click(function () {
        $('#choose').removeClass('layui-hide');
        $('#new').addClass('layui-hide');
        $('#group_id').removeAttr('disabled');
        $('#new input').attr('disabled','true');
        $('#choose_show').removeClass('btn-default');
        $('#choose_show').addClass('btn-info');
        $('#new_show').removeClass('btn-info');
        $('#new_show').addClass('btn-default');
        $('#group_id').val('').trigger("change");
    });
    $('#group_id').change(function () {
        var g_id=$('#group_id option:selected').val();
        $.get('{:url("get_group")}?g_id='+g_id,function (res) {
            if(res.group_budget_type==1){
                $('#budget').val(res.amount);
                $('#plat').val(res.platform);
                $('select[name="attr_adv_user_id"]').val(res.attr_adv_user_id);
                $('select[name="attr_adv_user_id"]').attr('disabled','true');
            }else if(res.group_budget_type==0){
                $('#budget').val('不限');
                $('#plat').val(res.platform);
                $('select[name="attr_adv_user_id"]').val(res.attr_adv_user_id);
                $('select[name="attr_adv_user_id"]').attr('disabled','true');
            }else {
                $('#budget').val('');
                $('#plat').val('');
                $('select[name="attr_adv_user_id"]').val('');
                $('select[name="attr_adv_user_id"]').removeAttr('disabled');
            }
        });
    });
    $('#adv_style').change(function () {
        var s_id=$('#adv_style option:selected').val();
        $('#put_location').empty();

        $.get('{:url("get_adv_location")}?s_id='+s_id,function (res) {
            if(res){
                $('#put_location').append("<option value='0'>选择投放位置</option>");
                $.each(res.adv_location,function () {
                    $('#put_location').append("<option value='"+this+"'>"+this+"</option>");
                });
                if(res.state){
                    $("#adv_title").removeClass('layui-hide');
                }else{
                    $("#adv_title").addClass('layui-hide');
                }
            }else {
                $('#put_location').append("<option value='0'>请先选择样式</option>");
                $("#adv_title").addClass('layui-hide');
                return false;
            }
        });
    });

</script>
</html>